package com.ed.task;

import com.ed.domain.ChatMessage;
import com.ed.mapper.IChatMessageMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Slf4j
public class AITask {
    @Autowired
    private IChatMessageMapper chatMessageMapper;
    @Async("taskExecutor")
    @Transactional
    public void recordChat(ChatMessage chatMessage){
        //先记录一下id值，再插入
        Integer quesId = chatMessage.getReplyId();
        chatMessage.setReplyId(null);
        chatMessageMapper.insert(chatMessage);
        //更新问题记录的rep_id
        //再进行问题id的更新
        ChatMessage chatMessage1 = new ChatMessage();
        chatMessage1.setId(quesId);
        chatMessage1.setReplyId(chatMessage.getId());
        chatMessageMapper.updateById(chatMessage1);
    }
}
